package product.service.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import product.api.ProductApi;
import product.model.ProductInfo;
import product.service.service.ProductService;

@RestController
@RequestMapping("/product")
public class ProductController implements ProductApi {
    @Autowired
    ProductService productService;
    @RequestMapping("/{productId}")
    public ProductInfo getProductInfoById(@PathVariable("productId") Integer id) {
        System.out.println("product-server接收到请求: " + id);
        return productService.getProductInfoById(id);
    }
    @RequestMapping("/p1")
    public String p1(@RequestParam("id") Integer id) {
        return "product-server接受到id: " + id;
    }
    @RequestMapping("/p2")
    public String p2(@RequestParam("id")Integer id,@RequestParam("name") String name) {
        return "product-server接受到id: " + id + ", name: " + name;
    }
    @RequestMapping("/p3")
    public String p3(ProductInfo productInfo) {
        return "product-server接受到ProductInfo: " + productInfo.toString();
    }
    @RequestMapping("/p4")
    public String p4(@RequestBody ProductInfo productInfo) {
        return "product-server接受到ProductInfo: " + productInfo.toString();
    }
}
